package com.shanling.shanlingcontroller.ui.fragment;

import android.util.SparseArray;

import com.shanling.shanlingcontroller.base.BaseLazyFragment;

/**
 * Created by ch1 on 2018/7/4.
 */

public class LoacalMusicFragmentFactory {
    private static SparseArray<BaseLazyFragment> mFragments ;
    public static BaseLazyFragment createFragment(int position){
        if(mFragments==null){
            mFragments=new SparseArray<BaseLazyFragment>();
        }
        BaseLazyFragment fragment = mFragments.get(position);
        if (fragment == null) {
            switch (position) {
                case 0:
                    fragment=new SongFragment();
                    break;
                case 1:
                    fragment=new SingerFragment();
                    break;
                case 2:
                    fragment=new AlbumFragment();
                    break;
                case 3:
                    fragment=new StyleFragment();
                    break;
                case 4:
                    fragment=new MusicFolderFragment();
                    break;
                case 5:
                    fragment=new CUEFragment();
                    break;
            }
            if (fragment != null) {
                mFragments.put(position, fragment);
            }
        }
        return fragment;
    }

    public static void onDestory(){
        if(mFragments!=null&&mFragments.size()>0){
            mFragments.clear();
            mFragments=null;
        }
    }
}
